<%-- 
    Document   : select
    Created on : 2024-6-2, 10:03:26
    Author     : Administrator
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
         <%
           response.setCharacterEncoding("utf-8");
           request.setCharacterEncoding("utf-8");
            String sno=request.getParameter("sno");
            String dno=request.getParameter("dno");
            String fno=request.getParameter("fno");
            String repairID=request.getParameter("repairID");
            
           Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");//反射机制 加载注册驱动
           String url="jdbc:sqlserver://127.0.0.1:1433;databasename=dbtest";//localhost
              Connection con=DriverManager.getConnection(url, "sa", "123123");
//创建与数据库连接的对象，指明具体连接的数据库，特别注意：数据库必须是存在的
              Statement stmt=con.createStatement();//创建执行SQL语句的对象Statement
              //String student="select sno,sname,sex,dno from student";//要执行的sql语句
              String student="select sno,sname,sex,dno from student where sno='"+sno+"'";
             ResultSet rs= stmt.executeQuery(student);//executeQuery方法返回一个ResulSet对象
               %>
               <table align="center" width="300" border="1"><tr><td>学号</td><td>姓名</td><td>性别</td><td>宿舍号</td></tr>
                  <%
              //String student="insert into student(sno,sname,sex,dno) values('05','中夏','女','001')";//空可以不插，非空一定插
              // String student="update student set sno='"+sno+"',sname='"+sname+"',sex='"+sex+"',dno='"+dno+"' where sno='"+sno+"'";
               if(rs.next()){
                   request.setAttribute("sno",rs.getString("sno"));
                   request.setAttribute("sname",rs.getString("sname"));
                   request.setAttribute("sex",rs.getString("sex"));
                   request.setAttribute("dno",rs.getString("dno"));
                   
                   request.getRequestDispatcher("selectfront.jsp").forward(request,response);
               }else{
                   request.setAttribute("message","查不到该记录，请重新核对!!");
                   request.getRequestDispatcher("selectfront.jsp").forward(request,response);
               }
              rs.close();
              stmt.close();
              con.close();
        %>
    </body>
</html>
